import config from "../../utils/config.js"
const upload = (file) => {
	const oldfile = JSON.parse(JSON.stringify(file));
	return new Promise((resolve, reject) => {
		uni.uploadFile({
			url: config.mobeilURL + '/common/uploadFile',
			filePath: oldfile.url,
			name: 'file', // 在FormData 中文件对应的属性名
			header: {
				"content-type": "multipart/form-data",
				"Authorization": uni.getStorageSync('cxbtoken')
			},
			success: res => {
				if (res.statusCode === 200 && JSON.parse(res.data).code === 200) {
					oldfile.url = JSON.parse(res.data).accessPath;
					oldfile.error = false;
					resolve(oldfile);
				} else {
					oldfile.error = true;
					resolve(oldfile);
				}
			},
			fail: err => {
				reject();
			}
		});
	})
}
export default {
	upload
}